#!/usr/bin/env python
# encoding: utf-8
'''
@author: Excelsiorly
@license: (C) Copyright 2022, All Rights Reserved.
@contact: excelsiorly@qq.com
@file: task2.py
@time: 2022/1/23 15:05
@desc:
'''
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(V, A, B):
    # write your code in Python 3.6
    n, m = len(V), len(A)
    # 前继哈希
    hash = {}
    for i in range(m):
        dep_list = hash.get(B[i], [])
        dep_list.append(A[i])
        hash[B[i]] = dep_list

    ans = 0
    dep_list = []
    # 遍历选取一个元素
    for i in range(n):
        if i in hash:
            dep_list = hash[i]
        else: dep_list = []
        for j in range(n):
            if i==j: continue
            # 检查是否有依赖关系
            # 没有就直接相加
            if not dep_list: ans = max(ans, V[i]+V[j])
            else:
                # 关系冲突就不能算进来
                if j in dep_list: continue
                else: ans = max(ans, V[i]+V[j])
    return ans
if __name__ == '__main__':
    v = [-3, 5, 7, 2, 3],
    A = [3, 1]
    B = [2, 4]
    RES = solution(v, A, B)
    print(RES)
